package com.falcon.web.controller;

import com.falcon.mvc.anno.LogTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @Data
    static public class TestRequest{
        private Integer id;
        private String name;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class TestResponse{
        private String request;
        private String data;
        private Date timestamp;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class BaseResult<T>{
        private int code;
        private String message;
        private T result;
    }

    @LogTime
    @GetMapping("/doGet")
    public BaseResult<TestResponse> doGet(TestRequest request) {
        TestResponse doGetSuccess = new TestResponse(request.toString(), "doGet success", new Date());
        return new BaseResult<>(0, "success", doGetSuccess);
    }

    @PostMapping("/doPost")
    public  BaseResult<TestResponse> doPost(@RequestBody TestRequest request) {
        TestResponse doGetSuccess = new TestResponse(request.toString(), "doGet success", new Date());
        return new BaseResult<>(1, "post error", doGetSuccess);
    }

}
